#pragma once

#ifndef _WIN32
#include <hiredis/hiredis.h>
#include <hiredis/async.h>
#include <string>
#include "common/define/noncopyable.h"

/**
 * @brief redis客户端
 */
class redis_client final : public noncopyable
{
public:
    redis_client() = default;
    ~redis_client();
public:
    /**
     * @brief 连接redis
     * @param host
     * @param port
     */
    bool connect(const std::string &host, const int32_t port = 6379);
    
    bool connect_ac(const std::string &host, const int32_t port = 6379);

    /**
     * @brief 重连redis
     */
    bool reconnect();

    void set(const std::string& key, const std::string &value);
    
    std::string get(const std::string& key);

    bool del(const std::string &key);

    void set_ac(const std::string& key, const std::string &value);
    
    std::string get_ac(const std::string& key);

    bool del_ac(const std::string &key);


    /**
     * @brief 断线回调函数
     */
    //void disconnect_callback(const redisAsyncContext *c, int status);
private:
    void process_error();
private:
    std::string m_host;
    int32_t m_port{ 6379 };
    redisContext* m_context{ nullptr };
    redisReply* m_reply{ nullptr };

    redisAsyncContext* m_context_ac{ nullptr };
};

#endif